<!DOCTYPE html>
<html class="x-admin-sm" xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/lib/layui/layui.js}" charset="utf-8"></script>
    <script type="text/javascript" th:src="@{/js/xadmin.js}"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="layui-fluid">
    <div class="layui-row">
        <form class="layui-form">
            <div class="layui-form-item">
                <label for="content" class="layui-form-label">
                    <span class="x-red">*</span>内容</label>
                <div class="layui-input-inline">
                    <input type="text" id="content" autocomplete="off" class="layui-input" lay-verify="content">
                </div>
            </div>
            <span class="layui-form-item">
                <label for="content" class="layui-form-label"></label>
                <button class="layui-btn" lay-filter="edit" lay-submit="" style="width: 120px">确定</button>
            </span>
        </form>
    </div>
</div>
<script>
    let id = null;
    let sheetName = null;
    //获取url中?及后面的字符串
    const query = window.location.search.substring(1);
    const vars = query.split("&");
    for (let i = 0; i < vars.length; i++) {
        const pair = vars[i].split("=");
        if (pair[0] === "id")
            id = pair[1];
        if (pair[0] === "sheetName")
            sheetName = pair[1];
    }
</script>
<script>
    layui.use(['form', 'layer', 'jquery'],
        function () {
            const $ = layui.jquery;
            const form = layui.form,
                layer = layui.layer;

            //自定义验证
            form.verify({
                content: function (value) {
                    if (null == value || value === "" || value.trim() === "")
                        return "请输入内容";
                }
            });

            //监听提交
            form.on('submit(edit)',
                function () {
                    const data = {ques: {"id": id, "content": $('#content').val()}, "sheetName": sheetName};
                    $.post({
                        url: "/updateQues",
                        async: false,
                        contentType: "application/json",
                        data: JSON.stringify(data),
                        success: function (data) {
                            if (data === "success") {
                                layer.msg('修改成功', {icon: 1, time: 1000},
                                    function () {
                                        //关闭当前frame
                                        xadmin.close();

                                        // 可以对父窗口进行刷新
                                        xadmin.father_reload();
                                    });
                            } else
                                layer.alert("修改失败", {icon: 5})
                        }
                    });
                    return false;
                });
        });
</script>
<script>const _hmt = _hmt || [];
(function () {
    const hm = document.createElement("script");
    hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
    const s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
})();</script>
</body>
</html>